/**==============================================
 * 模块导入区
 */

const { app } = require('photoshop');
const { localFileSystem: fs } = require("uxp").storage;
// const { executeAsModal } = require("photoshop").core;
// const { batchPlay } = require("photoshop").action;
const k = require('./js/modle/modle_lib');
/**======================================
 * 测试区
 */
// let doc = app.activeDocument;
// let layer = doc.layers[0];
//  D:/Own/Art/UI/psd
let test_n = k.kers_test.kers_t_number;

//const selectLayer = k.selectLayer;
//let sl= selectLayer(layer.id);//.then(value=>{return "value"})
//let kl =k.runModalFunction(sl.then(value=>{return "value"}),"Select Layer").then(value=>{return "value"});
//console.log(selectLayer(layer.id).then(value=>{return "value"},reason=>{return "asss"}));
//k.runModalFunction(selectLayer(layer.id),"Select Layer");
//const ctionCommands = async () => { await k.selectLayer(layer.id)}

/**======================================
 * HTML 业务
 */
let path = document.getElementById('exportPath').value;
//document.querySelector('confirmExport').addEventListener('click', () => { test1(); });
document.querySelector('#confirmExport').addEventListener('click',test1);
// 获取 select 标签的选中值

//let selectedValue = selectElement.value;

/**======================================
* Photoshop 业务
*/


async function exportImage(doc, saveType, entry) {

    let Options = 12;
    if (saveType == "png" || "PNG") {
        return actionCmd_png = async () => {
            if (!Options) {
                await doc.saveAs.png(entry);
            } else if (Options <= 9 & Options >= 0) {
                await doc.saveAs.png(entry, { compression: Options }, true);
            } else {
                alert("png 的压缩数值不在 0~9 之间---默认6");
            }
        }
    } else if (saveType == "jpg" || "JPG" || "JPEG") {
        return actionCmd_jpg = async () => {
            if (Options >= 0 & Options <= 12) {
                await doc.saveAs.jpg(entry, { quality: Options }, true);
            } else {
                alert("jpg 品质不在 0~12 之间---默认12");
            }
        }
    } else if (saveType == "psd" || "PSD") {
        await doc.saveAs.psd(entry);
    } else {
        alert("格式错误/n暂时只有--jpg--png--psd-- 3种格式 ");
    }


}


async function test1() {

    console.log("aaaaaaaaaaaaaaaaaaa");
}

/**
 * 切单图逻辑
 * ============
 * 1.选中图层
 * 2.转换智能对象
 * 3.打开智能对象
 * 4.如果带有蒙版--导出尺寸蒙版
 * 5.根据蒙版做选区
 * 6.根据选区裁剪画布
 * 7.导出图标
 * 8.关闭本文档
 * 9.历史记录后退回切图前状态----
 * 
 *  */ 

/**
 * 批量图层导出
 * ===========
 * 1.便利所有图层--包含 图层组 子级↓
 * 2.找到带有标识的 图层 或 图层组
 * 3.选中图层 或 图层组
 * 
 * 
 */





// aveType = async (saveType) => {

//     if (saveType == "PNG") {
//         return await saveType_PNG(entryPng, 6, true);
//     }
//     if (saveType == "JPG") {
//         return await saveType_JPG(entryPng, 12, true);
//     }
//     if (saveType == "PSD") {
//         return await saveType_PSD(entryPng);
//     } else {
//         console.log("其他")
//     }
//     const saveType_PNG = async (entry, Options = 6, asCopy = true) => {

//         await doc.saveAs.png(entry, { compression: Options }, asCopy);

//     }
//     const saveType_JPG = async (entry, Options = 12, asCopy = true) => {

//         await doc.saveAs.png(entry, { quality: Options }, asCopy);

//     }
//     const saveType_PSD = async (entry) => {

//         await doc.saveAs.psd(entry,Options);

//     }
// }

